#ifndef __BSP_MLX90614_H__
#define __BSP_MLX90614_H__

#include "driver/i2c_master.h"
#include "driver/gpio.h"
#include "bsp_i2c.h"
#include "esp_err.h"

// MLX90614 I2C 地址
#define BSP_MLX90614_ADDR 0x5A

// MLX90614 寄存器地址
#define MLX90614_REG_TA 0x06    // 环境温度
#define MLX90614_REG_TOBJ1 0x07 // 物体温度1
#define MLX90614_REG_TOBJ2 0x08 // 物体温度2

// 温度转换常数
#define MLX90614_TEMP_CONVERSION 0.02f  // 温度转换系数
#define MLX90614_TEMP_OFFSET 273.15f    // 开尔文到摄氏度的偏移

// 配置结构体
typedef struct {
    uint8_t i2c_addr;
    uint32_t timeout_ms;
} bsp_mlx90614_config_t;

// 设备句柄类型
typedef struct {
    i2c_master_dev_handle_t dev_handle;
    i2c_master_bus_handle_t bus_handle;
    const bsp_mlx90614_config_t *config;
} bsp_mlx90614_handle_t;

// 默认配置
#define BSP_MLX90614_CONFIG_DEFAULT() { \
    .i2c_addr = BSP_MLX90614_ADDR, \
    .timeout_ms = 1000 \
}

// 函数声明
esp_err_t bsp_mlx90614_init(i2c_master_bus_handle_t bus_handle, const bsp_mlx90614_config_t *config, bsp_mlx90614_handle_t *handle);
esp_err_t bsp_mlx90614_get_temperatures(bsp_mlx90614_handle_t *handle, float *ambient_temp, float *obj1_temp, float *obj2_temp);
esp_err_t bsp_mlx90614_read_ambient_temp(bsp_mlx90614_handle_t *handle, float *temperature);
esp_err_t bsp_mlx90614_read_object_temp(bsp_mlx90614_handle_t *handle, float *temperature);
esp_err_t bsp_mlx90614_delete(bsp_mlx90614_handle_t *handle);

#endif